package cn.edu.cqvie.jdk8.stream2;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class StreamTest2 {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("hello", "world", "hello world");
        NullPointerException nullPointerException = new NullPointerException("my exception");
        try (Stream<String> stream = list.stream()) {
            stream.onClose(() -> {
                System.out.println("aaaa");
                throw new NullPointerException("first exception");
            }).onClose(() -> {
                System.out.println("bbbb");
                //suppressed exceptions 压制的异常
                throw new NullPointerException("second exception");
            }).onClose(() -> {
                System.out.println("cccc");
            }).forEach(System.out::println);
        }


    }
}
